package com.atguigu.spzx.order.controller;

import com.atguigu.spzx.model.dto.order.OrderInfoDto;
import com.atguigu.spzx.model.entity.order.OrderInfo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.h5.TradeVo;
import com.atguigu.spzx.order.service.OrderInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderInfoController {

    @Autowired
    OrderInfoService orderInfoService;

    @GetMapping("/auth/trade")
    public Result<TradeVo> trade(){
        TradeVo tradeVo = orderInfoService.getTrade();
        return Result.ok(tradeVo);
    }

    @PostMapping("/auth/submitOrder")
    public Result submitOrder(@RequestBody OrderInfoDto orderInfoDto){
        Long orderId = orderInfoService.submitOrder(orderInfoDto);
        return Result.ok(orderId);
    }

    @GetMapping("/auth/buy/{skuId}")
    public Result<TradeVo> buy(@PathVariable Long skuId){
        TradeVo tradeVo = orderInfoService.buy(skuId);
        return Result.ok(tradeVo);
    }


    @GetMapping("/auth/{orderId}")
    public Result<OrderInfo> getOrderInfoById(@PathVariable Long orderId){
        OrderInfo orderInfo = orderInfoService.getOrderInfoById(orderId);
        return Result.ok(orderInfo);
    }


    @GetMapping("/auth/getOrderInfoByOrderNo/{orderNo}")
    public OrderInfo getOrderInfoByOrderNo(@PathVariable String orderNo){
        OrderInfo orderInfo= orderInfoService.getOrderInfoByOrderNo(orderNo);
        return orderInfo;
    }

    @GetMapping("/auth/{page}/{limit}")
    public Result<PageInfo<OrderInfo>> getOrderListByPage(@PathVariable int page,@PathVariable int limit,
                                                          Integer orderStatus){
        PageInfo<OrderInfo> pageInfo= orderInfoService.getOrderListByPage(page,limit,orderStatus);
        return Result.ok(pageInfo);
    }
}
